package SupermarketTest;

import java.util.Scanner;

public class shoppingTest {
    public static void test() {

    }

    static Supermarket t;

    public static void main(String[] args) {
        t = new Supermarket();
        t.setMarketName("泰克超市");
        Goods[] g = new Goods[5];
        for (int j = 0; j < g.length; j++) {
            g[j] = new Goods();
        }
        g[0].setIndex(1);
        g[0].setGoodsName("电脑");
        g[0].setPrice(6888);

        g[1].setIndex(2);
        g[1].setGoodsName("手机");
        g[1].setPrice(1999);

        g[2].setIndex(3);
        g[2].setGoodsName("冰箱");
        g[2].setPrice(5888);

        g[3].setIndex(4);
        g[3].setGoodsName("鸡蛋");
        g[3].setPrice(23.66);

        g[4].setIndex(5);
        g[4].setGoodsName("饮料");
        g[4].setPrice(5.5);
        t.setA(g);

        Member[] m = new Member[2];
        for (int i = 0; i < m.length; i++) {
            m[i] = new Member();
        }
        m[0].setUserName("张三");
        m[0].setPassWord("123456");

        m[1].setUserName("李四");
        m[1].setPassWord("123456");
        t.setMembers(m);
        Bag b=new Bag();
        System.out.println("-----------欢迎来到" + t.getMarketName() + "购物-----------");
        boolean isSuccess=false;
        System.out.println("请输入用户名");
        Scanner sc = new Scanner(System.in);
        String username;
        username = sc.nextLine();

        System.out.println("请输入密码");
        String password;
        password = sc.nextLine();

        while (!isSuccess) {
            Member[] members;
            members = t.members();
            for (int l = 0; l < members.length; l++) {
                Member member = t.members()[l];
                if (username.equals(members[l].getUserName()) && password.equals(members[l].getPassWord())) {
                    System.out.println("用户名在会员系统中");
                    isSuccess = true;
                    break;
                }
            }
            if (!isSuccess) {
                System.err.println("用户名或密码错误");
            }
        }
        System.out.println("-----------欢迎"+username+"来到"+t.getMarketName()+"购物------------");
        Goods[] goods = t.getA();
        for (int i = 0; i < goods.length; i++) {
            System.out.println(goods[i].getIndex() + "\t" + goods[i].getGoodsName() + "\t" + goods[i].getPrice() + "元");
        }
        System.out.println("-----------------------------");
        System.out.println("请输入商品编号");
        Scanner sv= new Scanner(System.in);
        int index = sv.nextInt();
        System.out.println("请输入商品数量");
        int count = sv.nextInt();
        Goods good=goods[index];
        b.setGoods(good);
        b.setCount(count);


        System.out.println("您购买的商品"+b.getGoods().getGoodsName()+"单价为："+b.getTotalPrice()+"元");
    }
}

